package rickyGame.game.action.state
{
	import ricky.utils.TimeServer;
	import ricky.game.action.Act2D;
	
	import rickyGame.game.Fighter;
	import rickyGame.game.action.ActionHelper;
	
	/**
	 * 持续一定时间的状态行动基类
	 */
	public class StateAct extends Act2D
	{
		public function StateAct(actor:Fighter, animProperty:String,endTime:Number)
		{
			super(actor);
			this._animProperty=animProperty;
			_endTime=endTime;
		}
		
		override public function begin():void
		{
			_state=1;
			_startTime=TimeServer.now();
			_states=Fighter(actor).stateNames;
			_states.push(this);
			
			if(this._effectNext)
				ActionHelper.inst.addAct(_effectNext);
		}
		
		override public	function action(timeline:Number):void
		{
			if(_state<1) //如果没有初始化
				return;
			if(timeline>=_endTime)
			{
				this.complete();
			}
		}
		
		override public function end():void
		{
			var i:int=_states.indexOf(this);
			if(i>=0)
				_states.splice(i,1);
			super.end();
		}
		
		override public function dispose():void
		{
			super.dispose();
		}
		//
		protected var _states:Array;
		protected var _startTime:Number;//开始时间毫秒数
		protected var _endTime:Number;//持续时间毫秒数
	}
}